import Shop from '../common/bean/Shop'
import http from '@ohos.net.http'
class ShopService{
  baseURL:string='http://192.168.0.8:3000'
  page:number=1

  getShopList():Promise<Shop[]>{
    return new Promise((resolve,reject)=>{
      //1 创建http的请求对象
      let httpRequest=http.createHttp()

      //2 发送请求
      httpRequest.request(
        `${this.baseURL}/shops?_page=${this.page}&_limit=3`,
        {
          method:http.RequestMethod.GET
        }
      ).then(
        resp=>{
          if(resp.responseCode===200){
            console.log('查询商铺成功',resp.result)
            resolve(JSON.parse(resp.result.toString()))
          }
          else{
            console.log('查询商铺信息失败！error:',JSON.stringify(resp))
            reject('查询商铺失败！')
          }
        }
      ).catch(error=>{
        console.log('查询商铺信息失败！error:',JSON.stringify(error))
        reject('查询商铺失败！')
      })
    })
  }
}

const shopService=new ShopService()
export default shopService as ShopService